package ${%^controllerPath^%};

import ${%^modelPath^%}.${%^type^%};
import ${%^servicePath^%}.${%^type^%}Service;
import com.project.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

${%^imports^%}

@RestController
@RequestMapping("/${%^tableName^%}")
public class ${%^type^%}Controller {

    @Autowired
    private ${%^type^%}Service service;

    @GetMapping("/list")
    public Map get(@RequestParam Map<String, Object> map){
        String sp = (String) map.get("page");
        String sl = (String) map.get("limit");
        Integer page = Integer.parseInt(sp);
        Integer limit = Integer.parseInt(sl);
        page = (page-1) * limit;
        map.put("page", page);
        map.put("limit", limit);
        Map<String, Object> res = service.list(map);
        res.put("code", 0);
        res.put("msg", "成功");
        return res;
    }

    @GetMapping("/query")
    public R query(@RequestBody ${%^type^%} data){
        List<${%^type^%}> query = service.query(data);
        return R.success().setData(query);
    }

    @PostMapping("/update")
    public R update(@RequestBody ${%^type^%} data){
        Integer update = service.update(data);
        return R.success("修改成功").setData(update);
    }

    @PostMapping("/insert")
    public R insert(@RequestBody ${%^type^%} data){
        Integer num = service.insert(data);
        return R.success("成功添加"+num+"条数据").setData(num);
    }

    @PostMapping("/deletes")
    public R delete(@RequestBody List<${%^tablePrimaryKeyType^%}> list){
        if ( list.size() == 0) return R.success().setData(0);
        Integer num = service.deletes(list);
        return R.success("成功删除"+num+"条数据").setData(num);
    }
}